﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace MaoCaiJun.DataBase.Configuration
{
    public partial class DBSControl : UserControl
    {
        System.Collections.Generic.Dictionary<string, DbsAnalysis.MaoCaiJunDataBaseMapping> EditdbsMap = new System.Collections.Generic.Dictionary<string, MaoCaiJun.DataBase.Configuration.DbsAnalysis.MaoCaiJunDataBaseMapping>();

        public DBSControl()
        {
            InitializeComponent();

            ////////////

            initDBS();

        }

        //初始化
        #region DBS 初始化
        private void initDBS()
        {
            System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument();
            xdoc.LoadXml(Properties.Resources.Setting);
            //xdoc.Load(setting_config);
            string[] s_type;
            string[] s_sqltype;



            //功能
            comboBoxFunction.Items.Clear();
            System.Xml.XmlNodeList xmls = xdoc.SelectNodes("Setting/Function/Item");
            for (int i = 0; i < xmls.Count; i++)
            {
                comboBoxFunction.Items.Add(getValue(xmls[i], "value"));
            }
            //数据类型
            xmls = xdoc.SelectNodes("Setting/Type/Item");
            s_type = new string[xmls.Count];
            for (int i = 0; i < xmls.Count; i++)
            {
                s_type[i] = getValue(xmls[i], "value");
            }
            Type.Items.AddRange(s_type);
            //Sql类型
            xmls = xdoc.SelectNodes("Setting/Sql-Type/Item");
            s_sqltype = new string[xmls.Count];
            for (int i = 0; i < xmls.Count; i++)
            {
                s_sqltype[i] = getValue(xmls[i], "value");
            }
            SqlType.Items.AddRange(s_sqltype);
        }
        private string getValue(System.Xml.XmlNode xnd, string str)
        {
            if (xnd.Attributes[str] == null)
            {
                return "";
            }
            return xnd.Attributes[str].Value;
        }
        private string getValue(DataGridViewRow dgvr, string str)
        {
            if (dgvr.Cells[str].Value == null)
            {
                return "";
            }
            return dgvr.Cells[str].Value.ToString();
        }
        public void GetNodes(string path, string searchPattern, TreeNodeCollection Node)
        {//Directorie
            string[] d = System.IO.Directory.GetDirectories(path);
            foreach (string item in d)
            {
                TreeNode tn = new TreeNode(System.IO.Path.GetFileNameWithoutExtension(item));
                tn.Name = "folder";
                tn.ToolTipText = item;
                tn.ImageKey = "folder.png";
                tn.SelectedImageKey = "folder_go.png";
                tn.ContextMenuStrip = this.contextMenuStrip1;

                Node.Add(tn);
                GetNodes(item, searchPattern, tn.Nodes);
            }
            //File
            string[] f = System.IO.Directory.GetFiles(path, searchPattern);
            foreach (string item in f)
            {
                TreeNode tn = new TreeNode(System.IO.Path.GetFileNameWithoutExtension(item));
                tn.Name = "file";
                tn.ToolTipText = item;
                tn.ImageKey = "html.png";
                tn.SelectedImageKey = "html_go.png";
                Node.Add(tn);
                tn.ContextMenuStrip = this.contextMenuStrip1;

                DbsAnalysis.MaoCaiJunDataBaseMapping map = new MaoCaiJun.DataBase.Configuration.DbsAnalysis.MaoCaiJunDataBaseMapping();
                map.OpenDBS(item);
                tn.Tag = map;


                foreach (MaoCaiJun.DataBase.Configuration.DbsAnalysis.Namespace n in map.Namespace)
                {
                    TreeNode tnN = new TreeNode(n.Name);
                    tnN.ToolTipText = n.Name;
                    tnN.Name = "namespace";
                    tnN.ImageKey = "script.png";
                    tnN.SelectedImageKey = "script_edit.png";
                    tn.Nodes.Add(tnN);
                    tnN.Tag = n;
                    tnN.ContextMenuStrip = this.contextMenuStrip1;

                    foreach (MaoCaiJun.DataBase.Configuration.DbsAnalysis.Class c in n.Class)
                    {
                        TreeNode tnC = new TreeNode(c.Name);
                        tnC.Name = "class";
                        tnC.ToolTipText = c.Name;
                        tnC.ImageKey = "page_white_c.png";
                        tnC.SelectedImageKey = "page_edit.png";
                        tnN.Nodes.Add(tnC);
                        tnC.Tag = c;
                        tnC.ContextMenuStrip = this.contextMenuStrip1;

                    }
                }
            }

        }


        #endregion DBS 初始化

        private string _path;
        private DbsAnalysis.MaoCaiJunDataBaseMapping _maoCaiJunDataBaseMapping;
        private DbsAnalysis.Class _class;

        public string dbFilter = "*.dbs";
        public bool OpenDBSDirectory(string path)
        {
            treeView1.Nodes["root"].Nodes.Clear();
            EditdbsMap.Clear();
            if (!System.IO.Directory.Exists(path)) { return false; }

            treeView1.Nodes["root"].ToolTipText = path;
            GetNodes(path, dbFilter, treeView1.Nodes["root"].Nodes);
            treeView1.Nodes["root"].Expand();
            return true;
        }
        public bool SeveDBSDirectory()
        {

            //if (treeView1.SelectedNode != null && treeView1.SelectedNode.Tag != null && treeView1.SelectedNode.Tag.GetType().FullName == "MaoCaiJun.DataBase.Configuration.DbsAnalysis.Class")
            //{
            GetDBS();

            //}

            foreach (System.Collections.Generic.KeyValuePair<string, DbsAnalysis.MaoCaiJunDataBaseMapping> item in EditdbsMap)
            {
                item.Value.SeveDBS(item.Key);
            }

            EditdbsMap.Clear();
            return true;
        }
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node.Tag == null) { return; }
            if (e.Node.Tag.GetType().FullName == "MaoCaiJun.DataBase.Configuration.DbsAnalysis.Class")
            {
                MaoCaiJun.DataBase.Configuration.DbsAnalysis.Class c = e.Node.Tag as MaoCaiJun.DataBase.Configuration.DbsAnalysis.Class;
                GetDBS();
                SetDBS(c);
                _path = e.Node.Parent.Parent.ToolTipText;
                _maoCaiJunDataBaseMapping = e.Node.Parent.Parent.Tag as MaoCaiJun.DataBase.Configuration.DbsAnalysis.MaoCaiJunDataBaseMapping;
                _class = c;

            }
        }

        private void SetDBS(MaoCaiJun.DataBase.Configuration.DbsAnalysis.Class c)
        {
            if (c == null)
            {
                splitContainer1.Panel2.Enabled = false;
            }
            else
            {
                splitContainer1.Panel2.Enabled = true;

                textBoxTableNameInterface.Text = c.TableNameInterface;
                textBoxName.Text = c.Name;
                textBoxTable.Text = c.Table;
                textBoxSummary.Text = c.Summary;
                textBoxConnectionString.Text = c.ConnectionString;
                comboBoxFunction.Text = c.Function.ToString();
                comboBoxConnectionLocation.Text = c.ConnectionLocation.ToString();
                comboBoxType.Text = c.Type.ToString();

                dataGridView1.Rows.Clear();
                //
                SetProperty(c.ID);
                //
                foreach (MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property item in c.Property)
                {
                    SetProperty(item);
                }

                comboBoxById_DropDown(null, null);
                comboBoxById.Text = c.ID.Name;

            }
        }
        private void SetProperty(MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property p)
        {
            int i = dataGridView1.Rows.Add();
            dataGridView1.Rows[i].Cells["_Name"].Value = p.Name;
            dataGridView1.Rows[i].Cells["SqlIndex"].Value = p.SqlIndex;
            dataGridView1.Rows[i].Cells["SqlLength"].Value = p.SqlLength;
            dataGridView1.Rows[i].Cells["SqlName"].Value = p.SqlName;
            dataGridView1.Rows[i].Cells["SqlNotNull"].Value = p.SqlNotNull;
            dataGridView1.Rows[i].Cells["SqlType"].Value = p.SqlType;
            dataGridView1.Rows[i].Cells["SqlValue"].Value = p.SqlValue;
            dataGridView1.Rows[i].Cells["Summary"].Value = p.Summary;
            dataGridView1.Rows[i].Cells["Type"].Value = p.Type;
            dataGridView1.Rows[i].Cells["Value"].Value = p.Value;
        }

        private void GetDBS()
        {
            if (_class == null)
            {
                return;
            }
            else
            {


                _class.TableNameInterface = textBoxTableNameInterface.Text;
                _class.Name = textBoxName.Text;
                _class.Table = textBoxTable.Text;
                _class.Summary = textBoxSummary.Text;
                _class.ConnectionString = textBoxConnectionString.Text;
                _class.Function = (MaoCaiJun.DataBase.Sys.Data.FunctionType)System.Enum.Parse(typeof(MaoCaiJun.DataBase.Sys.Data.FunctionType), comboBoxFunction.Text, true);
                _class.ConnectionLocation =(MaoCaiJun.DataBase.Sys.Data.ConnectionLocation)System.Enum.Parse(typeof(MaoCaiJun.DataBase.Sys.Data.ConnectionLocation), comboBoxConnectionLocation.Text,true);
                _class.Type = (MaoCaiJun.DataBase.Sys.Data.SqlType)System.Enum.Parse(typeof(MaoCaiJun.DataBase.Sys.Data.SqlType), comboBoxType.Text,true);

                _class.Property.Clear();

                foreach (DataGridViewRow item in dataGridView1.Rows)
                {
                    DbsAnalysis.Property p = GetProperty(item);
                    if (string.IsNullOrEmpty(p.Name)) { continue; }
                    if (p.Name == comboBoxById.Text)
                    {
                        _class.ID = p;

                    }
                    else
                    {
                        _class.Property.Add(p);
                    }
                    // 
                }
                if (!EditdbsMap.ContainsKey(_path))
                {
                    EditdbsMap.Add(_path, _maoCaiJunDataBaseMapping);
                }
            }
        }

        private MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property GetProperty(DataGridViewRow item)
        {
            DbsAnalysis.Property p = new MaoCaiJun.DataBase.Configuration.DbsAnalysis.Property();
            p.Name = System.Convert.ToString(item.Cells["_Name"].Value);
            p.SqlIndex = System.Convert.ToString(item.Cells["SqlIndex"].Value);
            p.SqlLength = System.Convert.ToString(item.Cells["SqlLength"].Value);
            p.SqlName = System.Convert.ToString(item.Cells["SqlName"].Value);
            p.SqlNotNull = System.Convert.ToBoolean(item.Cells["SqlNotNull"].Value);
            p.SqlType = System.Convert.ToString(item.Cells["SqlType"].Value);
            p.SqlValue = System.Convert.ToString(item.Cells["SqlValue"].Value);
            p.Summary = System.Convert.ToString(item.Cells["Summary"].Value);
            p.Type = System.Convert.ToString(item.Cells["Type"].Value);
            p.Value = System.Convert.ToString(item.Cells["Value"].Value);

            return p;
        }

        private void comboBoxById_DropDown(object sender, EventArgs e)
        {
            comboBoxById.Items.Clear();
            foreach (DataGridViewRow item in dataGridView1.Rows)
            {
                if (item.Cells["_Name"].Value == null) { continue; }
                comboBoxById.Items.Add(item.Cells["_Name"].Value);
            }
        }

        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {
            TreeNode tn = treeView1.SelectedNode;

            if (tn == null)
            { return; }
            if (tn.Name == "root")
            {
                createDirectoryToolStripMenuItem.Visible = true;
                createFileToolStripMenuItem.Visible = true;
                createToolStripMenuItem.Visible = false;
                toolStripSeparator1.Visible = false;
                changeToolStripMenuItem.Visible = false;
                toolStripSeparator2.Visible = true;
                saveToolStripMenuItem.Visible = true;
                toolStripSeparator3.Visible = false;
                delToolStripMenuItem.Visible = false;
                toolStripSeparator4.Visible = true;
                openDirectoryToolStripMenuItem.Visible = true;
            }
            else if (tn.Name == "folder")
            {
                createDirectoryToolStripMenuItem.Visible = true;
                createFileToolStripMenuItem.Visible = true;
                createToolStripMenuItem.Visible = false;
                toolStripSeparator1.Visible = true;
                changeToolStripMenuItem.Visible = true;
                toolStripSeparator2.Visible = true;
                saveToolStripMenuItem.Visible = true;
                toolStripSeparator3.Visible = true;
                delToolStripMenuItem.Visible = true;
                toolStripSeparator4.Visible = true;
                openDirectoryToolStripMenuItem.Visible = true;

            }
            else if (tn.Name == "file")
            {
                createDirectoryToolStripMenuItem.Visible = false;
                createFileToolStripMenuItem.Visible = false;
                createToolStripMenuItem.Visible = true;
                toolStripSeparator1.Visible = true;
                changeToolStripMenuItem.Visible = true;
                toolStripSeparator2.Visible = true;
                saveToolStripMenuItem.Visible = true;
                toolStripSeparator3.Visible = true;
                delToolStripMenuItem.Visible = true;
                toolStripSeparator4.Visible = true;
                openDirectoryToolStripMenuItem.Visible = true;

                //
                createToolStripMenuItem.Text = "新建命名空间";
            }
            else if (tn.Name == "namespace")
            {
                createDirectoryToolStripMenuItem.Visible = false;
                createFileToolStripMenuItem.Visible = false;
                createToolStripMenuItem.Visible = true;
                toolStripSeparator1.Visible = true;
                changeToolStripMenuItem.Visible = true;
                toolStripSeparator2.Visible = true;
                saveToolStripMenuItem.Visible = false;
                toolStripSeparator3.Visible = false;
                delToolStripMenuItem.Visible = true;
                toolStripSeparator4.Visible = false;
                openDirectoryToolStripMenuItem.Visible = false;

                //
                createToolStripMenuItem.Text = "新建类";
            }
            else if (tn.Name == "class")
            {
                createDirectoryToolStripMenuItem.Visible = false;
                createFileToolStripMenuItem.Visible = false;
                createToolStripMenuItem.Visible = true;
                toolStripSeparator1.Visible = true;
                changeToolStripMenuItem.Visible = true;
                toolStripSeparator2.Visible = true;
                saveToolStripMenuItem.Visible = false;
                toolStripSeparator3.Visible = false;
                delToolStripMenuItem.Visible = true;
                toolStripSeparator4.Visible = false;
                openDirectoryToolStripMenuItem.Visible = false;

                //
                createToolStripMenuItem.Text = "新建项";
            }
            //if (treeView1.SelectedNode.Tag.GetType().FullName == "MaoCaiJun.DataBase.Configuration.DbsAnalysis.Class")
            //{
            //}
        }

        private void createDirectoryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode tn = treeView1.SelectedNode;
            if (tn == null)
            { return; }
            string path = System.IO.Path.Combine(tn.ToolTipText, "New Dbs Folder");
            if (System.IO.Directory.Exists(path))
            {
                for (int i = 1; true; i++)
                {
                    if (!System.IO.Directory.Exists(path + " (" + i + ")"))
                    {
                        path += " (" + i + ")";
                        break;
                    }
                }
            }
            System.IO.Directory.CreateDirectory(path);
            TreeNode tnNew = tn.Nodes.Add(System.IO.Path.GetFileNameWithoutExtension(path));
            tnNew.ToolTipText = path;
            tnNew.ContextMenuStrip = contextMenuStrip1;
            tnNew.Name = "folder";
            tnNew.ImageKey = "folder.png";
            tnNew.SelectedImageKey = "folder_go.png";

            tn.Expand();
        }
        private void createFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode tn = treeView1.SelectedNode;
            if (tn == null)
            { return; }
            string path = System.IO.Path.Combine(tn.ToolTipText, "New Dbs File");
            string f = dbFilter.Remove(0, dbFilter.IndexOf('.'));
            if (System.IO.File.Exists(path + f))
            {
                for (int i = 1; true; i++)
                {
                    if (System.IO.File.Exists(path + " (" + i + ")" + f))
                    {
                        path += " (" + i + ")";
                        break;
                    }
                }
            }
            DbsAnalysis.MaoCaiJunDataBaseMapping map = new MaoCaiJun.DataBase.Configuration.DbsAnalysis.MaoCaiJunDataBaseMapping();
            map.SeveDBS(path + f);
            TreeNode tnNew = tn.Nodes.Add(System.IO.Path.GetFileNameWithoutExtension(path));
            tnNew.ToolTipText = path;
            tnNew.ContextMenuStrip = contextMenuStrip1;
            tnNew.Name = "file";
            tnNew.ImageKey = "html.png";
            tnNew.SelectedImageKey = "html_go.png";
            tnNew.Tag = map;

            tn.Expand();
        }
        private void createToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode tn = treeView1.SelectedNode;
            if (tn == null)
            { return; }
            switch (tn.Tag.GetType().FullName)
            {
                case "MaoCaiJun.DataBase.Configuration.DbsAnalysis.MaoCaiJunDataBaseMapping":
                    MaoCaiJun.DataBase.Configuration.DbsAnalysis.MaoCaiJunDataBaseMapping map = tn.Tag as MaoCaiJun.DataBase.Configuration.DbsAnalysis.MaoCaiJunDataBaseMapping;
                    MaoCaiJun.DataBase.Configuration.DbsAnalysis.Namespace n = new MaoCaiJun.DataBase.Configuration.DbsAnalysis.Namespace();
                    n.Name = "New Namespace";
                    map.Namespace.Add(n);
                    TreeNode tnN = tn.Nodes.Add(n.Name);
                    tnN.ToolTipText = n.Name;
                    tnN.Name = "namespace";
                    tnN.ImageKey = "script.png";
                    tnN.SelectedImageKey = "script_edit.png";
                    tnN.Tag = n;
                    tnN.ContextMenuStrip = this.contextMenuStrip1;
                    break;
                case "MaoCaiJun.DataBase.Configuration.DbsAnalysis.Namespace":
                    MaoCaiJun.DataBase.Configuration.DbsAnalysis.Namespace nSpace = tn.Tag as MaoCaiJun.DataBase.Configuration.DbsAnalysis.Namespace;
                    MaoCaiJun.DataBase.Configuration.DbsAnalysis.Class c = new MaoCaiJun.DataBase.Configuration.DbsAnalysis.Class();
                    c.Name = "New Class";
                    nSpace.Class.Add(c);
                    TreeNode tnC = tn.Nodes.Add(c.Name);
                    tnC.Name = "class";
                    tnC.ToolTipText = c.Name;
                    tnC.ImageKey = "page_white_c.png";
                    tnC.SelectedImageKey = "page_edit.png";
                    tnC.Tag = c;
                    tnC.ContextMenuStrip = this.contextMenuStrip1;
                    break;
                case "MaoCaiJun.DataBase.Configuration.DbsAnalysis.Class":
                    dataGridView1.Rows.Add();
                    break;
                default:
                    break;
            }



        }
        private void changeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode tn = treeView1.SelectedNode;
            if (tn == null)
            { return; }
            tn.BeginEdit();
        }
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //TreeNode tn = treeView1.SelectedNode;
            //if (tn == null)
            //{ return; }
            //saveDBS(tn);
            SeveDBSDirectory();
        }
        private void saveDBS(TreeNode tn)
        {
            if (tn.Name == "folder" || tn.Name == "root")
            {
                foreach (TreeNode item in tn.Nodes)
                {
                    saveDBS(item);
                }
            }

            else if (tn.Name == "file")
            {
                MaoCaiJun.DataBase.Configuration.DbsAnalysis.MaoCaiJunDataBaseMapping map = tn.Tag as MaoCaiJun.DataBase.Configuration.DbsAnalysis.MaoCaiJunDataBaseMapping;
                map.SeveDBS(tn.ToolTipText);
            }
        }
        private void delToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                TreeNode tn = treeView1.SelectedNode;
                if (tn == null)
                { return; }
                if (tn.Tag == null && System.IO.Directory.Exists(tn.ToolTipText))
                {
                    System.IO.Directory.Delete(tn.ToolTipText);
                    tn.Remove();
                    return;
                }
                switch (tn.Tag.GetType().FullName)
                {
                    case "MaoCaiJun.DataBase.Configuration.DbsAnalysis.MaoCaiJunDataBaseMapping":
                        if (System.IO.File.Exists(tn.ToolTipText))
                        {
                            System.IO.File.Delete(tn.ToolTipText);
                        }
                        tn.Remove();
                        break;
                    case "MaoCaiJun.DataBase.Configuration.DbsAnalysis.Namespace":
                        MaoCaiJun.DataBase.Configuration.DbsAnalysis.MaoCaiJunDataBaseMapping map = tn.Parent.Tag as MaoCaiJun.DataBase.Configuration.DbsAnalysis.MaoCaiJunDataBaseMapping;
                        MaoCaiJun.DataBase.Configuration.DbsAnalysis.Namespace n = tn.Tag as MaoCaiJun.DataBase.Configuration.DbsAnalysis.Namespace;
                        map.Namespace.Remove(n);

                        if (!EditdbsMap.ContainsKey(tn.Parent.ToolTipText))
                        {
                            EditdbsMap.Add(tn.Parent.ToolTipText, map);
                        }
                        tn.Remove();
                        break;
                    case "MaoCaiJun.DataBase.Configuration.DbsAnalysis.Class":
                        map = tn.Parent.Parent.Tag as MaoCaiJun.DataBase.Configuration.DbsAnalysis.MaoCaiJunDataBaseMapping;
                        n = tn.Parent.Tag as MaoCaiJun.DataBase.Configuration.DbsAnalysis.Namespace;
                        MaoCaiJun.DataBase.Configuration.DbsAnalysis.Class c = tn.Tag as MaoCaiJun.DataBase.Configuration.DbsAnalysis.Class;
                        n.Class.Remove(c);

                        if (!EditdbsMap.ContainsKey(tn.Parent.Parent.ToolTipText))
                        {
                            EditdbsMap.Add(tn.Parent.Parent.ToolTipText, map);
                        }
                        tn.Remove();
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void openDirectoryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode tn = treeView1.SelectedNode;
            if (tn == null)
            { return; }
            if (tn.Name == "file")
            {
                System.Diagnostics.Process.Start(System.IO.Path.GetDirectoryName(tn.ToolTipText));
            }
            else
            {
                System.Diagnostics.Process.Start(tn.ToolTipText);
            }


        }



        private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            TreeNode tn = e.Node;
            if (tn == null)
            { return; }
            if (tn.Tag == null && System.IO.Directory.Exists(tn.ToolTipText))
            {
                e.CancelEdit = true;

                return;
            }
            switch (tn.Tag.GetType().FullName)
            {
                case "MaoCaiJun.DataBase.Configuration.DbsAnalysis.MaoCaiJunDataBaseMapping":
                    //if (System.IO.File.Exists(tn.ToolTipText))
                    //{
                    //    System.IO.File.Delete(tn.ToolTipText);
                    //}
                    e.CancelEdit = true;
                    break;
                case "MaoCaiJun.DataBase.Configuration.DbsAnalysis.Namespace":
                    MaoCaiJun.DataBase.Configuration.DbsAnalysis.MaoCaiJunDataBaseMapping map = tn.Parent.Tag as MaoCaiJun.DataBase.Configuration.DbsAnalysis.MaoCaiJunDataBaseMapping;
                    MaoCaiJun.DataBase.Configuration.DbsAnalysis.Namespace n = tn.Tag as MaoCaiJun.DataBase.Configuration.DbsAnalysis.Namespace;
                    n.Name = e.Label;

                    if (!EditdbsMap.ContainsKey(tn.Parent.ToolTipText))
                    {
                        EditdbsMap.Add(tn.Parent.ToolTipText, map);
                    }

                    break;
                case "MaoCaiJun.DataBase.Configuration.DbsAnalysis.Class":
                    map = tn.Parent.Parent.Tag as MaoCaiJun.DataBase.Configuration.DbsAnalysis.MaoCaiJunDataBaseMapping;
                    n = tn.Parent.Tag as MaoCaiJun.DataBase.Configuration.DbsAnalysis.Namespace;
                    MaoCaiJun.DataBase.Configuration.DbsAnalysis.Class c = tn.Tag as MaoCaiJun.DataBase.Configuration.DbsAnalysis.Class;

                    textBoxName.Text = e.Label;
                    //c.Name = e.Label;


                    //if (!EditdbsMap.ContainsKey(tn.Parent.Parent.ToolTipText))
                    //{
                    //    EditdbsMap.Add(tn.Parent.Parent.ToolTipText, map);
                    //}

                    break;
                default:
                    break;
            }
        }

    }
}